/**
 * Created by Administrator on 2016/11/2.
 *
 */
var Alert=function (data) {
    if(!data)
        return;
    this.id=data.id;//要弹出层的id
    this.title=data.title;//弹出层标题
    this.width=(data.width||500);//弹出层宽度
    this.height=(data.height||300);//弹出层宽度
    this.confirm=data.confirm||function () {};//确认按钮执行函数
    this.cancel=data.cancel||function () {};//取消按钮执行函数

    this.panel=document.createElement('div');
    this.panel.className='alert';
    this.panel.style.width=this.width+'px';
    this.panel.style.height=this.height+'px';
    /*实际内容*/
    this.panelContent=document.createElement('div');
    this.panelContent.className='panelContent';
    this.content=document.getElementById(this.id);
    this.panelContent.style.height=(this.height-60)+'px';
    this.panelContent.appendChild(this.content);
    /*灰掉*/
    this.blackPanel=document.createElement('div');
    this.blackPanel.className='black';
    /*关闭按钮*/
    this.closeBtn=document.createElement('span');
    this.closeBtn.className='closeBtn';
    /*标题*/
    this.titlePanel=document.createElement('div');
    this.titlePanel.innerHTML=this.title;
    this.titlePanel.className='titlePanel';
    /*取消*/
    this.cancelBtn=document.createElement('span');
    this.cancelBtn.className='cancelBtn btn';
    this.cancelBtn.innerHTML=data.cancelName||"取消";
    /*确认*/
    this.confirmBtn=document.createElement('span');
    this.confirmBtn.className='confirmBtn btn';
    this.confirmBtn.innerHTML=data.confirmName||"确认";
    /*底部按钮*/
    this.btnPanel=document.createElement('div');
    this.btnPanel.className='btnPanel';
    this.btnPanel.style.width=(this.width-2)+'px';
    this.btnPanel.appendChild(this.cancelBtn);
    this.btnPanel.appendChild(this.confirmBtn);
};
Alert.prototype={
    /*初始化，显示弹出层*/
    init:function () {
        this.panel.appendChild(this.closeBtn);
        this.panel.appendChild(this.titlePanel);
        this.panel.appendChild(this.panelContent);
        this.panel.appendChild(this.btnPanel);
        document.body.appendChild(this.panel);
        document.body.appendChild(this.blackPanel);
        this.bindEvent();
        this.show();
        return this;
    },
    /*绑定按钮事件*/
    bindEvent:function () {
        var me=this;
        this.closeBtn.onclick=function () {
            //执行关闭取消方法
            if(confirm("您确定要关闭吗？")){
                me.cancel();
                me.hide();
            }
        };
        this.confirmBtn.onclick=function () {
            me.confirm();
        };
        this.cancelBtn.onclick=function () {
            if(confirm("您确定要关闭吗？")){
                me.cancel();
                me.hide();
            }
        }
    },
    hide:function () {
        this.panel.style.display='none';
        document.getElementsByClassName('black')[0].style.display='none';
        return this;
    },
    show:function () {
        this.panel.style.display='block';
        document.getElementsByClassName('black')[0].style.display='block';
        return this;
    }
};
